package org.javaboy.order.service;

import org.javaboy.order.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class OrderService {
    @Autowired
    AccountService accountService;
    @Autowired
    OrderMapper orderMapper;

    public Map<String, Object> order(Integer userId, Integer commodityId, Integer count) {
        //扣款
        double money = count * 100.0;
        accountService.deduce(userId, money);
        //下单
        orderMapper.createOrder(userId, commodityId, count, money);
        Map<String, Object> map = new HashMap<>();
        map.put("result", "下订单成功");
        return map;
    }
}
